//
//  LoginNavController.swift
//  TalkeTv
//
//  Created by lhf on 2024/9/19.
//

import UIKit

class LoginNavController: UINavigationController,UINavigationControllerDelegate {

    var popGesture:UIGestureRecognizerDelegate?
    
    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        viewController.navigationItem.backBarButtonItem = UIBarButtonItem.init(title: "", style: .plain, target: nil, action: nil)
    }
    
    // 解决自定义leftBarButtonItem导致右滑失效
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        // 根据 栈 先进后出
        if viewControllers[0] == viewController {
            // 根控制器
            // 还原代理
            interactivePopGestureRecognizer?.delegate = (popGesture!)
        } else {
            // 非控制器
            // 清空手势代理就能实现滑动返回，iOS6不支持
            interactivePopGestureRecognizer?.delegate = nil
        }
        // 如果当前控制器为根控制器，则使手势失效，不然手势会将根控制器移除
        if viewControllers.count == 1 {
            interactivePopGestureRecognizer?.isEnabled = false
        } else {
            interactivePopGestureRecognizer?.isEnabled = true
        }
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        super.pushViewController(viewController, animated: true)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.delegate = self;
        
        // 记录系统手势代理
        self.popGesture = self.interactivePopGestureRecognizer?.delegate
        
        //统一导航条样式
        let font = UIFont.systemFont(ofSize: 17.0)
        let textAttributes = [NSAttributedString.Key.font:font,NSAttributedString.Key.foregroundColor:UIColor.black]
        self.navigationBar.titleTextAttributes = textAttributes
        self.navigationBar.tintColor = UIColor.black
        self.navigationBar.isTranslucent = true
        self.navigationBar.setBackgroundImage(UIImage.init(), for: .default)
        self.navigationBar.shadowImage = UIImage()

        // Do any additional setup after loading the view.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
